<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>产生一条回溯跟踪(backtrace)</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="ref.errorfunc.html">« 错误处理 函数</a></li>
      <li style="float: right;"><a href="function.debug-print-backtrace.html">debug_print_backtrace »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.errorfunc.html">错误处理 函数</a></li>
    <li>产生一条回溯跟踪(backtrace)</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.debug-backtrace" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">debug_backtrace</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.3.0, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">debug_backtrace</span> &mdash; <span class="dc-title">产生一条回溯跟踪(backtrace)</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.debug-backtrace-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>debug_backtrace</strong></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$options</code><span class="initializer"> = <strong><code>DEBUG_BACKTRACE_PROVIDE_OBJECT</code></strong></span></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$limit</code><span class="initializer"> = 0</span></span>): <span class="type">array</span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>debug_backtrace()</strong></span> 产生一条 PHP 的回溯跟踪(backtrace)。
  </p>
 </div>

 
 <div class="refsect1 parameters" id="refsect1-function.debug-backtrace-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">options</code></dt>

     <dd>

      <p class="para">
       这个参数是以下选项的位掩码：
       <table class="doctable table">
        <caption><strong><span class="function"><strong>debug_backtrace()</strong></span> 选项</strong></caption>
        
         <tbody class="tbody">
          <tr>
           <td>DEBUG_BACKTRACE_PROVIDE_OBJECT</td>
           <td>
            是否填充 &quot;object&quot; 的索引。
           </td>
          </tr>

          <tr>
           <td>DEBUG_BACKTRACE_IGNORE_ARGS</td>
           <td>
            是否忽略 &quot;args&quot; 的索引，包括所有的 function/method 的参数，能够节省内存开销。
           </td>
          </tr>

         </tbody>
        
       </table>

      </p>
     </dd>

    
    
     <dt>
<code class="parameter">limit</code></dt>

     <dd>

      <p class="para">
       这个参数能够用于限制返回堆栈帧的数量。默认为（<code class="parameter">limit</code>=<code class="literal">0</code>），返回所有的堆栈帧。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>

 
 <div class="refsect1 returnvalues" id="refsect1-function.debug-backtrace-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   返回一个包含众多关联数组的 <span class="type">array</span>。
   以下为有可能返回的元素：
  </p>
  <p class="para">
   <table class="doctable table">
    <caption><strong>有可能从 <span class="function"><strong>debug_backtrace()</strong></span> 返回的元素</strong></caption>
    
     <thead>
      <tr>
       <th>名字</th>
       <th>类型</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>function</td>
       <td><span class="type">string</span></td>
       <td>
        当前的函数名，参见：<a href="language.constants.predefined.html" class="link">__FUNCTION__</a>。
       </td>
      </tr>

      <tr>
       <td>line</td>
       <td><span class="type">int</span></td>
       <td>
        当前的行号。参见：<a href="language.constants.predefined.html" class="link">__LINE__</a>。
       </td>
      </tr>

      <tr>
       <td>file</td>
       <td><span class="type">string</span></td>
       <td>
        当前的文件名。参见：<a href="language.constants.predefined.html" class="link">__FILE__</a>。
       </td>
      </tr>

      <tr>
       <td>class</td>
       <td><span class="type">string</span></td>
       <td>
        当前 <a href="language.oop5.html" class="link">class</a>
        的名称。参见<a href="language.constants.predefined.html" class="link">__CLASS__</a>
       </td>
      </tr>

      <tr>
       <td>object</td>
       <td><span class="type">object</span></td>
       <td>
        当前的 <a href="language.oop5.html" class="link">object</a>。
       </td>
      </tr>

      <tr>
       <td>type</td>
       <td><span class="type">string</span></td>
       <td>
        当前调用的类型。如果是一个方法，会返回 &quot;-&gt;&quot;。如果是一个静态方法，会返回 &quot;::&quot;。如果是一个函数调用，则返回空。
       </td>
      </tr>

      <tr>
       <td>args</td>
       <td><span class="type">array</span></td>
       <td>
        如果在一个函数里，这会列出函数的参数。如果是在一个被包含的文件里，会列出包含的文件名。
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.debug-backtrace-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-513">
    <p><strong>示例 #1 <span class="function"><strong>debug_backtrace()</strong></span> 范例</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;filename:&nbsp;/tmp/a.php<br /><br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">a_test</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"\nHi:&nbsp;</span><span style="color: #0000BB">$str</span><span style="color: #DD0000">"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">debug_backtrace</span><span style="color: #007700">());<br />}<br /><br /></span><span style="color: #0000BB">a_test</span><span style="color: #007700">(</span><span style="color: #DD0000">'friend'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;<br /></span><br /><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;filename:&nbsp;/tmp/b.php<br /></span><span style="color: #007700">include_once&nbsp;</span><span style="color: #DD0000">'/tmp/a.php'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>
     执行 <var class="filename">/tmp/b.php</var> 返回的结果类似于以下：
    </p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
Hi: friend
array(2) {
[0]=&gt;
array(4) {
    [&quot;file&quot;] =&gt; string(10) &quot;/tmp/a.php&quot;
    [&quot;line&quot;] =&gt; int(10)
    [&quot;function&quot;] =&gt; string(6) &quot;a_test&quot;
    [&quot;args&quot;]=&gt;
    array(1) {
      [0] =&gt; &amp;string(6) &quot;friend&quot;
    }
}
[1]=&gt;
array(4) {
    [&quot;file&quot;] =&gt; string(10) &quot;/tmp/b.php&quot;
    [&quot;line&quot;] =&gt; int(2)
    [&quot;args&quot;] =&gt;
    array(1) {
      [0] =&gt; string(10) &quot;/tmp/a.php&quot;
    }
    [&quot;function&quot;] =&gt; string(12) &quot;include_once&quot;
  }
}
</pre></div>
    </div>
   </div>
  </p>
 </div>

 
 <div class="refsect1 seealso" id="refsect1-function.debug-backtrace-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.trigger-error.html" class="function" rel="rdfs-seeAlso">trigger_error()</a> - 产生一个用户级别的 error/warning/notice 信息</span></li>
    <li class="member"><span class="function"><a href="function.debug-print-backtrace.html" class="function" rel="rdfs-seeAlso">debug_print_backtrace()</a> - 打印一条回溯。</span></li>
   </ul>
  </p>
 </div>

</div></div></div></body></html>